package com.building.controller;

import com.building.common.R;
import com.building.controller.BaseController.BaseController;
import com.building.entity.ShoppingOrder;
import com.building.enums.REnum;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.web.bind.annotation.*;

/**
 * @author yinjiahui
 * @create 2021-04-12 21:08
 */
@RestController
@RequestMapping("shoppingOrder")
public class ShoppingOrderController extends BaseController {

    /**
     * 根据用户id查询订单中的商品
     *
     * @param userId
     * @return
     */
    @GetMapping("selectShoppingOrderByUserId/{userId}")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="根据用户id查询订单中的商品",name="userId",dataType="Integer",required=true,value="用户id",defaultValue="这个是默认值，可以不写"),
    })
    @ApiResponses({
            @ApiResponse(code=400,message="请求参数没填好"),
            @ApiResponse(code=404,message="请求路径没有或页面跳转路径不对")
    })
    public R selectShoppingOrderByUserId(@PathVariable("userId") Integer userId){
        return R.result(REnum.SUCCESS_QUERY,this.shoppingOrderService.selectShoppingOrderByUserId(userId));
    }

    /**
     * 新增或修改订单
     *
     * @param shoppingOrder
     * @return
     */
    @PostMapping("insertOrUpdateShoppingOrder")
    @ApiResponses({
            @ApiResponse(code=400,message="请求参数没填好"),
            @ApiResponse(code=404,message="请求路径没有或页面跳转路径不对")
    })
    public R insertOrUpdateShoppingOrder(@RequestBody ShoppingOrder shoppingOrder){
        return this.shoppingOrderService.insertOrUpdateShoppingOrderByShoppingOrderId(shoppingOrder);
    }

    /**
     * 根据订单id和用户id删除订单中的商品
     *
     * @param shoppingOrderId
     * @param userId
     * @return
     */
    @DeleteMapping("deleteShoppingOrderByShoppingOrderIdAndUserId/{shoppingOrderId}/{userId}")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="根据订单id删除订单中的商品",name="shoppingOrderId",dataType="Integer",required=true,value="订单id",defaultValue="这个是默认值，可以不写"),
            @ApiImplicitParam(paramType="根据用户id删除订单中的商品",name="userId",dataType="Integer",required=true,value="用户id",defaultValue="这个是默认值，可以不写"),
    })
    @ApiResponses({
            @ApiResponse(code=400,message="请求参数没填好"),
            @ApiResponse(code=404,message="请求路径没有或页面跳转路径不对")
    })
    public R deleteShoppingOrderByShoppingOrderIdAndUserId(@PathVariable("shoppingOrderId") Integer shoppingOrderId,@PathVariable("userId") Integer userId){
        this.shoppingOrderService.deleteShoppingOrderByShoppingOrderIdAndUserId(shoppingOrderId,userId);
        return R.result(REnum.SUCCESS_DELETE);
    }



}
